﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Globalization;
using System.Web;
using System.Web.Caching;
using ResourceBlender.DAL;

namespace ResourceBlender.NET {
    public partial class ASPNETBLL {
        /// <summary>
        /// Gets a cached copy of a sorted dictionary containing the languages of all resources in the database, sorted by English Name. 
        /// Only existing resources are used to populate the dictionary, and only non empty language codes are included.
        /// Key = LanguageCode, Value = CultureInfo
        /// </summary>
        /// <returns>A dictionary containing the CultureInfo of all resources in the database</returns>
        public static IEnumerable<KeyValuePair<string, CultureInfo>> GetUniqueLanguages() {
            string cacheKey = "uniqueLangs";
            var langs = HttpContext.Current.Cache[cacheKey] as IEnumerable<KeyValuePair<string, CultureInfo>>;
            if(langs == null) {
                langs = ResourceBlenderDAL.GetUniqueLanguages();
                HttpContext.Current.Cache[cacheKey] = langs;
            }
            return langs;
        }
    }
}
